Skip to content

设置窗口客户区偏移 - SetClientLocation

函数简介

设置绑定窗口客户区左上角在截图/远程帧坐标系中的偏移量 (x, y)

适用于 VNC 全屏截图 等场景:远程画面是整个 framebuffer,插件无法像本地前台那样通过窗口句柄自动得到客户区在屏幕上的位置。调用本接口后,可在不修改任何截图参数的前提下,让脚本仍按窗口相对坐标编写逻辑。

坐标转换规则

方向规则
截图CaptureCaptureMat(0,0,0,0)不做任何修改,始终按帧/全屏原样截取。
找图/找色返回坐标内部在返回前 减去 (x, y),得到窗口相对坐标。
鼠标移动/点击传入窗口相对坐标时,内部 加上 (x, y) 再发送到远程/屏幕。
GetCursorPos返回窗口相对坐标,内部 减去 (x, y)

(0, 0) 可清除偏移,恢复默认行为。


典型使用场景

  1. 使用 BindWindowEx 绑定,displayvncmousevnc(或前台键鼠 + VNC 截图)。
  2. SetConfig 中配置 VNC 地址与端口。
  3. 人工确认目标窗口客户区在 VNC 画面中的左上角位置,调用 SetClientLocation
  4. 脚本中区域参数、鼠标坐标均按窗口相对坐标书写;找图结果自动转为窗口坐标。

接口名称

SetClientLocation

DLL调用

int SetClientLocation(long ola, int x, int y);

参数说明

参数名类型说明
ola长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
x整数型客户区左上角在截图/远程帧中的 X 偏移。
y整数型客户区左上角在截图/远程帧中的 Y 偏移。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int ret = ola.SetClientLocation(100, 200);
if (ret == 1) {
    // 操作成功
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
int ret = ola.SetClientLocation(100, 200);
if (ret == 1)
{
    // 操作成功
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
ret = ola.SetClientLocation(100, 200)
if ret == 1:
    pass  # 操作成功
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
int ret = ola.SetClientLocation(100, 200);
if (ret == 1) {
    // 操作成功
}
cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.SetClientLocation(100, 200)
if(ret == 1) {
    // 操作成功
}
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.SetClientLocation(100, 200)
If ret = 1 Then
    ' 操作成功
End If
text
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.SetClientLocation(100, 200)
.如果真 (ret = 1)
    ' 操作成功
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.SetClientLocation(100, 200);
if(ret == 1){
    // 操作成功
}
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.SetClientLocation(100, 200)
如果真 (ret = 1)
{
    // 操作成功
}
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
int32_t ret = ola.SetClientLocation(100, 200);
if (ret == 1) {
    // 操作成功
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
SetClientLocation(instance, 100, 200);
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SetClientLocation(long ola, int x, int y);

long instance = CreateCOLAPlugInterFace();
SetClientLocation(instance, 100, 200);
python
from ctypes import CDLL, c_int, c_int64, create_string_buffer

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.SetClientLocation(instance, 100, 200)

返回值

说明
1成功
0失败(如 OLA 对象无效)

受影响的接口

返回坐标会减去偏移(帧坐标 → 窗口相对坐标)

找图 / 匹配

  • MatchWindowsFromPtr / MatchWindowsFromPtrAll
  • MatchWindowsFromPath / MatchWindowsFromPathAll
  • MatchWindowsThresholdFromPtr / MatchWindowsThresholdFromPtrAll
  • MatchWindowsThresholdFromPath / MatchWindowsThresholdFromPathAll
  • FindWindowsFromPtr / FindWindowsFromPtrAll
  • FindWindowsFromPath / FindWindowsFromPathAll

找色 / 色块

  • FindColor / FindColorList / FindColorEx / FindColorListEx
  • FindMultiColor / FindMultiColorList
  • FindColorBlock / FindColorBlockList / FindColorBlockEx / FindColorBlockListEx

以上均为基于窗口截图CaptureMat)且返回坐标的接口。*Ptr、内存图类接口(如 MatchImageFromPtr)不受影响。

输入坐标会加上偏移(窗口相对坐标 → 帧坐标)

鼠标移动

鼠标位置读取(返回值减偏移)

  • GetCursorPos

间接受影响(使用当前光标位置,需先 MoveTo 到正确窗口坐标)

  • LeftClick / LeftDoubleClick / LeftDown / LeftUp
  • RightClick / RightDoubleClick / RightDown / RightUp
  • MiddleClick / MiddleDoubleClick / MiddleDown / MiddleUp
  • WheelUp / WheelDown

相对移动

  • MoveR 本身不传绝对坐标;效果依赖移动前的光标位置。

不受影响的接口

类别说明
截图CaptureCaptureGifGetScreenData*LockDisplay 等;含 (0,0,0,0) 全屏。
取色/比色GetColorCmpColor*GetColorNum 等;坐标按帧坐标使用,若要用窗口相对坐标需自行 x+offsetX, y+offsetY
内存图MatchImageFromPtrFindImageFromPtr*Ptr / 非绑定窗口源图接口。
坐标转换ClientToScreenScreenToClient
OCROcrOcrExOcrDetails 等(当前版本未接入偏移转换)。
动画匹配MatchAnimationFromPtrMatchAnimationFromPath(当前版本未接入偏移转换)。

注意事项

  1. 先绑定再设置:建议在 BindWindow / BindWindowEx 成功后调用;偏移按 OLA 实例 保存,与绑定窗口配合使用。
  2. 偏移需人工标定:VNC 画面里用外部工具量出客户区左上角像素位置,再填入 x, y
  3. 截图区域参数不变MatchWindows*(x1,y1,x2,y2) 等区域仍按帧/全屏坐标系传入(全屏常用 0,0,0,0);仅返回值转为窗口坐标。
  4. 取色坐标GetColor(x, y)x, y 为帧坐标;窗口相对取色请使用 GetColor(x+offsetX, y+offsetY)
  5. 解绑不清除:调用 UnBindWindow 不会自动清零偏移,需要时请 SetClientLocation(0, 0)

与其它模块的关系

模块关系
窗口VNC 绑定后配合本接口实现「全屏帧 + 窗口逻辑坐标」。
图像识别MatchWindows*FindWindows* 返回坐标自动转换。
鼠标MoveTo 系列与点击类接口自动转换。
设置VNC 端口等仍通过 SetConfig 配置。